|
|
|
|
|
|
|
You can take advantage of two solutions to the problems associated with the replacement of menus. First, you can duplicate all the necessary parent form functions on each child form. Unfortunately, this approach can lead to a bloated and hard-to-maintain program if you have several child forms with menus. |
|
|
|
|
|
|
|
|
An alternative solution is to include in the parent window's menu all the menus that are necessary for all child windows. Then you can place code in the child form's GotFocus and LostFocus events to show (and hide) the parent's menus that are applicable to that child form when that child form has the focus. For example, in a word processing program, you want the File and Help menus to be available all the time, but you want the Edit and Format menus available only when you are working on a document. To make the Edit and Format menus visible, you can place code like the following in the appropriate child form's GotFocus event procedure: |
|
|
|
|
|
|
|
|
mnuEdit.Visible = True
mnuFormat.Visible = True |
|
|
|
|
|
|
|
|
The following code, placed in the child form's LostFocus event procedure, takes care of making the Edit and Format menus invisible again: |
|
|
|
|
|
|
|
|
mnuEdit.Visible = False
mnuFormat.Visible = False |
|
|
|
|
|
|
|
|
To make sure that any menu code in the parent form acts on the proper child form, use the parent form's ActiveForm property as described in the preceding section. |
|
|
|
|
|
|
|
|
One of the other benefits of working with MDI applications is that you can easily manage all the child forms. Visual Basic offers a number of tools that make it easy for your users to access the multiple forms that are open inside the MDI form. Your program can provide the users with the means to arrange the child windows automatically. You can even provide a menu item that keeps up with all the open child windows and lets the users access one of them by selecting it from the menu. These capabilities are particularly useful if the users will be switching back and forth between multiple tasks or multiple files in the application. |
|
|
|
|
|
|
|
|
Using Automatic Organization |
|
|
|
|
|
|
|
|
One way that users can access multiple forms is by displaying each form on the screen in a particular organizational style. This capability provides the users with access to each form with just a click of a mouse button. The key to this functionality is the MDI form's Arrange method. The Arrange method organizes all the child forms of the application in a particular pattern. Each of these patterns results in at least a portion of each form's being visible to the users, and they are commonly used by MDI-compliant Windows applications. |
|
|
|
|
|
|
|
|
To use the Arrange method, you specify the name of the MDI form, the method itself, and a constant representing the pattern that you want to use for the arrangement of the forms. The following line of code illustrates the use of the method: |
|
|
|
|
|
|
|
|
mdiMain.Arrange vbCascade |
|
|
|
|
|